package com.lagou.edu.mvcframework.interceptor;

import com.lagou.edu.mvcframework.pojo.Handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;

/**
 * @ClassName SecurityInterceptor
 * @Description TODO
 * @Auth ying.xiao
 * @Date 2021/2/23
 * @Version 1.0.0
 */
public class SecurityInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Handler handlerRe = (Handler) handler;
        HashSet<String> securitySet = handlerRe.getSecuritySet();
        String username = request.getParameter("username");
        if (null == username||username.isEmpty()){
            return false;
        }
        return securitySet.contains(username);
    }
}
